/*
 * @Author: 孙大大
 * @Date: 2022-04-10 11:43:21
 * @LastEditTime: 2022-04-12 11:32:42
 * @FilePath: \黑马面面\src\store\modules\question.js
 */
import { getQuestionList, changePages, delRow } from "@/api/questions";

const state = {
  questionList: [],
  page: 1,
  pagesize: 5,
  questionList1: [],
};

const mutations = {
  setQuestionList(state, data) {
    state.questionList = data;
  },
  changePage(state, data) {
    state.page = data;
    console.log(7777777, state.page);
  },
  updateQuestionList(state, data) {
    state.questionList = [];
    state.questionList = data;
  },
  // delRow(state, data) {
  //   state.questionList = data;
  // },
  // updateQuestionList1(state, data) {
  //   state.questionList1 = [];
  //   state.questionList1 = data;
  // },
};

const actions = {
  async getQuestionList(context) {
    let res = await changePages({
      page: context.state.page,
      pagesize: context.state.pagesize,
    });
    context.commit("setQuestionList", res);
  },
  changePage(context, data) {
    console.log(888888, data);
    context.commit("changePage", data);
  },
  // async delRow(context, id) {
  //   let res = await delRow(id);
  //   context.commit("delRow", res);
  // },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
